package io.github.enbool.util;

import org.springframework.stereotype.Component;

import io.github.enbool.domain.Organization;
import io.github.enbool.enums.ResultEnum;
import io.github.enbool.exception.NoPermissionException;
import io.github.enbool.exception.UserException;


@Component
public class PermissionCheckUtil {	
	
	public static void checkOrganization(Long organizationId) {		
		Organization organization = UserUtil.getUserOrganization();
		if(organization == null) {
			throw new UserException(ResultEnum.USER_NO_ORGANIZATION);
		}
		if(!organization.getId().equals(organizationId)) {
			throw new NoPermissionException("没有权限操作其他Organization的资源！");
		}
	}

	public static void checkUer(Long id) {		
		if(!UserUtil.getUser().getId().equals(id)) {
			throw new NoPermissionException("没有权限操作其他User的资源！");
		}
	}
}